#pragma once
// DRAFT
#include "EventHandle.h"

template<typename ClassType>
class GetEventHandle;
template<typename ClassType>
class SetEventHandle;

template <typename T>
class Property
{
protected:
	T _value;
	inline T GetValue()
	{
		if (GetEvent != nullptr)
			GetEvent->ProcDrv(this->_value);
		return this->_value;
	}

	inline T Changed(T value)
	{
		if (SetEvent != nullptr)
			SetEvent->ProcDrv(this->_value, value);
		return value;
	}
public:
	GetEventHandle<T> *GetEvent = nullptr;
	SetEventHandle<T> *SetEvent = nullptr;
	Property() { }
	Property(T v) { this->_value = Changed(v); }
	virtual operator T()	// while request value
	{
		return GetValue();
	}
	virtual Property& operator=(T v)	// T to class
	{
		this->_value = Changed(v);
		return *this;
	}
	virtual Property& operator=(Property& p)	// class to class
	{
		T v = p.GetValue();
		this->_value = Changed(v);
		return *this;
	}
};

template<typename ClassType>
class GetEventHandle : public EventHandle<ClassType&>
{
public:
	void Bind(Property<ClassType>& Object)
	{
		Object.GetEvent = this;
	}
};

template<typename ClassType>
class SetEventHandle : public EventHandle<const ClassType, ClassType&>
{
public:
	void Bind(Property<ClassType>& Object)
	{
		Object.SetEvent = this;
	}
};